﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DIS_DAO.DTO;
using DIS_DAO.DAO;
using DIS_DAO.Helpers;
using System.Data;

namespace DIS_DAO
{
    public class DataProvider: IDataProvider
    {
        #region CONSTRUCTOR

        public DataProvider(string strPath)
        {
            GlobalVariables.DbConnectionString = strPath;
        }

        #endregion

        #region FUNCTIONS
        public List<FunctionsDTO> Functions_SelectAll()
        {
            var lstDto = new List<FunctionsDTO>();
            var rpt = new FunctionsDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(FunctionsDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public FunctionsDTO Functions_SelectByID(int id)
        {
            var rpt = new FunctionsDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return FunctionsDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Functions_Insert(FunctionsDTO obj)
        {
            var rpt = new FunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Functions_Delete(int id)
        {
            var rpt = new FunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Functions_Update(FunctionsDTO obj)
        {
            var rpt = new FunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        #endregion

        #region ROLE
        public List<RoleDTO> Role_SelectAll()
        {
            var lstDto = new List<RoleDTO>();
            var rpt = new RoleDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(RoleDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public RoleDTO Role_SelectByID(int id)
        {
            var rpt = new RoleDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return RoleDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Role_Insert(RoleDTO obj)
        {
            var rpt = new RoleDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Role_Delete(int id)
        {
            var rpt = new RoleDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Role_Update(RoleDTO obj)
        {
            var rpt = new RoleDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        #endregion

        #region ORDERS
        public List<OrdersDTO> Orders_SelectAll()
        {
            var lstDto = new List<OrdersDTO>();
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrdersDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public OrdersDTO Orders_SelectByID(int id)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return OrdersDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Orders_Insert(ref OrdersDTO obj)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(ref obj);
        }
        public bool Orders_Delete(int id)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Orders_Update(OrdersDTO obj)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<OrdersDTO> Orders_SelectByIDChemistWareHouse(int idchemistwarehouse)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<OrdersDTO>();
            var objDS = rpt.SelectByIDChemistWareHouse(idchemistwarehouse);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrdersDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<OrdersDTO> Orders_SelectByIDCustomer(int idcustomer)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<OrdersDTO>();
            var objDS = rpt.SelectByIDCustomer(idcustomer);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrdersDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<OrdersDTO> Orders_SelectByIDChemistWareHouseAndOrderDate(int idChemistWareHouse, DateTime orderdate)
        {
            var rpt = new OrdersDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<OrdersDTO>();
            var objDS = rpt.SelectByIDChemistWareHouseAndOrderDate(idChemistWareHouse, orderdate);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrdersDTO.Translate(row));
                }
            }
            return lstDto;
        }
        #endregion

        #region EMPLOYEE
        public List<EmployeeDTO> Employee_SelectAll()
        {
            var lstDto = new List<EmployeeDTO>();
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(EmployeeDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public EmployeeDTO Employee_SelectByID(int id)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return EmployeeDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Employee_Insert(EmployeeDTO obj)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Employee_Delete(int id)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Employee_Update(EmployeeDTO obj)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<EmployeeDTO> Employee_SelectByIDRole(int idrole)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<EmployeeDTO>();
            var objDS = rpt.SelectByIDRole(idrole);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(EmployeeDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<EmployeeDTO> Employee_SelectByIDChemistWareHouse(int idchemistwarehouse)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<EmployeeDTO>();
            var objDS = rpt.SelectByIDChemistWareHouse(idchemistwarehouse);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(EmployeeDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public EmployeeDTO Employee_SelectByUserName(string username)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<EmployeeDTO>();
            var objDS = rpt.SelectByUserName(username);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return EmployeeDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public EmployeeDTO Employee_SelectByUserNameAndPassword(string username, string password)
        {
            var rpt = new EmployeeDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<EmployeeDTO>();
            var objDS = rpt.SelectByUserNameAndPassword(username, password);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return EmployeeDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        #endregion

        #region DAILYREPORT
        public List<DailyReportDTO> DailyReport_SelectAll()
        {
            var lstDto = new List<DailyReportDTO>();
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(DailyReportDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public DailyReportDTO DailyReport_SelectByID(int id)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return DailyReportDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool DailyReport_Insert(DailyReportDTO obj)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool DailyReport_Delete(int id)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool DailyReport_Update(DailyReportDTO obj)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<DailyReportDTO> DailyReport_SelectByIDChemistWareHouse(int idchemistwarehouse)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<DailyReportDTO>();
            var objDS = rpt.SelectByIDChemistWareHouse(idchemistwarehouse);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(DailyReportDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public DailyReportDTO DailyReport_SelectByIDChemistWareHouseAndReportDate(int idchemistwarehouse, DateTime reportdate)
        {
            var rpt = new DailyReportDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<DailyReportDTO>();
            var objDS = rpt.SelectByIDChemistWareHouseAndReportDate(idchemistwarehouse, reportdate);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return DailyReportDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }

        #endregion

        #region WEEKLYREPORT
        public List<WeeklyReportDTO> WeeklyReport_SelectAll()
        {
            var lstDto = new List<WeeklyReportDTO>();
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(WeeklyReportDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public WeeklyReportDTO WeeklyReport_SelectByID(int id)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return WeeklyReportDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool WeeklyReport_Insert(WeeklyReportDTO obj)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool WeeklyReport_Delete(int id)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool WeeklyReport_Update(WeeklyReportDTO obj)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<WeeklyReportDTO> WeeklyReport_SelectByIDChemistWareHouse(int idchemistwarehouse)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<WeeklyReportDTO>();
            var objDS = rpt.SelectByIDChemistWareHouse(idchemistwarehouse);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(WeeklyReportDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public WeeklyReportDTO WeeklyReport_SelectByIDChemistWareHouseAndReportDate(int idChemistWareHouse, DateTime startdate, DateTime enddate)
        {
            var rpt = new WeeklyReportDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<WeeklyReportDTO>();
            var objDS = rpt.SelectByIDChemistWareHouseAndReportDate(idChemistWareHouse, startdate, enddate);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return WeeklyReportDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        #endregion

        #region LOCALPROMOTION
        public List<LocalPromotionDTO> LocalPromotion_SelectAll()
        {
            var lstDto = new List<LocalPromotionDTO>();
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(LocalPromotionDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public LocalPromotionDTO LocalPromotion_SelectByID(int id)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return LocalPromotionDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool LocalPromotion_Insert(LocalPromotionDTO obj)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool LocalPromotion_Delete(int id)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool LocalPromotion_DeleteByIDItemAndIDChemistWareHouse(int iditem, int idChemistWareHouse)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.DeleteByIDItemAndIDChemistWareHouse(iditem, idChemistWareHouse);
        }
        public bool LocalPromotion_Update(LocalPromotionDTO obj)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<LocalPromotionDTO> LocalPromotion_SelectByIDItem(int iditem)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<LocalPromotionDTO>();
            var objDS = rpt.SelectByIDItem(iditem);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(LocalPromotionDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<LocalPromotionDTO> LocalPromotion_SelectByIDChemistWareHouse(int idchemistwarehouse)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<LocalPromotionDTO>();
            var objDS = rpt.SelectByIDChemistWareHouse(idchemistwarehouse);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(LocalPromotionDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public LocalPromotionDTO LocalPromotion_SelectByIDItemAndIDChemistWareHouse(int iditem, int idchemistwarehouse)
        {
            var rpt = new LocalPromotionDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<LocalPromotionDTO>();
            var objDS = rpt.SelectByIDItemAndIDChemistWareHouse(iditem, idchemistwarehouse);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return LocalPromotionDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        #endregion

        #region ORDERDETAIL
        public List<OrderDetailDTO> OrderDetail_SelectAll()
        {
            var lstDto = new List<OrderDetailDTO>();
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrderDetailDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public OrderDetailDTO OrderDetail_SelectByID(int id)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return OrderDetailDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool OrderDetail_Insert(OrderDetailDTO obj)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool OrderDetail_Delete(int id)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool OrderDetail_DeleteByOrder(int idorder)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            return rpt.DeleteByOrder(idorder);
        }
        public bool OrderDetail_Update(OrderDetailDTO obj)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<OrderDetailDTO> OrderDetail_SelectByIDOrder(int idorder)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<OrderDetailDTO>();
            var objDS = rpt.SelectByIDOrder(idorder);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrderDetailDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<OrderDetailDTO> OrderDetail_SelectByIDItem(int iditem)
        {
            var rpt = new OrderDetailDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<OrderDetailDTO>();
            var objDS = rpt.SelectByIDItem(iditem);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(OrderDetailDTO.Translate(row));
                }
            }
            return lstDto;
        }
        #endregion

        #region NATIONALPROMOTION
        public List<NationalPromotionDTO> NationalPromotion_SelectAll()
        {
            var lstDto = new List<NationalPromotionDTO>();
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(NationalPromotionDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public NationalPromotionDTO NationalPromotion_SelectByID(int id)
        {
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return NationalPromotionDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool NationalPromotion_Insert(NationalPromotionDTO obj)
        {
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool NationalPromotion_Delete(int id)
        {
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool NationalPromotion_Update(NationalPromotionDTO obj)
        {
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public NationalPromotionDTO NationalPromotion_SelectByIDItem(int iditem)
        {
            var rpt = new NationalPromotionDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<NationalPromotionDTO>();
            var objDS = rpt.SelectByIDItem(iditem);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return NationalPromotionDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        #endregion

        #region CART
        public List<CartDTO> Cart_SelectAll()
        {
            var lstDto = new List<CartDTO>();
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(CartDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public CartDTO Cart_SelectByID(int id)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CartDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Cart_Insert(CartDTO obj)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Cart_Delete(string cartid, int recordid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(cartid, recordid);
        }
        public bool Cart_Update(CartDTO obj)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<CartDTO> Cart_SelectByItemID(int itemid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<CartDTO>();
            var objDS = rpt.SelectByItemID(itemid);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(CartDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<CartDTO> Cart_SelectByCartID(string cartid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<CartDTO>();
            var objDS = rpt.SelectByCartID(cartid);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(CartDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public CartDTO Cart_SelectByIDAndRecordID(string cartid, int recordid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<CartDTO>();
            var objDS = rpt.SelectByIDAndRecordID(cartid, recordid);
            if (objDS != null)
            {
                return CartDTO.Translate(objDS.Tables[0].Rows[0]);
            }
            return null;
        }
        public CartDTO Cart_SelectByRecordID(int recordid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByRecordID(recordid);
            if (objDS != null)
            {
                return CartDTO.Translate(objDS.Tables[0].Rows[0]);
            }
            return null;
        }
        public CartDTO Cart_SelectByIDAndItem(string cartid, int itemid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByIDAndItem(cartid, itemid);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CartDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Cart_Empty(string cartid)
        {
            var rpt = new CartDAO(GlobalVariables.DbConnectionString);
            return rpt.Empty(cartid);
        }
        #endregion

        #region ITEM
        public List<ItemDTO> Item_SelectAll()
        {
            var lstDto = new List<ItemDTO>();
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(ItemDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public ItemDTO Item_SelectByID(int id)
        {
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return ItemDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Item_Insert(ItemDTO obj)
        {
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Item_Delete(int id)
        {
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Item_Update(ItemDTO obj)
        {
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<ItemDTO> Item_SelectByIDCategory(int idcategory)
        {
            var rpt = new ItemDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<ItemDTO>();
            var objDS = rpt.SelectByIDCategory(idcategory);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(ItemDTO.Translate(row));
                }
            }
            return lstDto;
        }
        #endregion

        #region ROLEFUNCTIONS
        public List<RoleFunctionsDTO> RoleFunctions_SelectAll()
        {
            var lstDto = new List<RoleFunctionsDTO>();
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(RoleFunctionsDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public RoleFunctionsDTO RoleFunctions_SelectByID(int id)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return RoleFunctionsDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool RoleFunctions_Insert(RoleFunctionsDTO obj)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool RoleFunctions_Delete(int id)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool RoleFunctions_Update(RoleFunctionsDTO obj)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public List<RoleFunctionsDTO> RoleFunctions_SelectByIDRole(int idrole)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<RoleFunctionsDTO>();
            var objDS = rpt.SelectByIDRole(idrole);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(RoleFunctionsDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public List<RoleFunctionsDTO> RoleFunctions_SelectByIDFunction(int idfunction)
        {
            var rpt = new RoleFunctionsDAO(GlobalVariables.DbConnectionString);
            var lstDto = new List<RoleFunctionsDTO>();
            var objDS = rpt.SelectByIDFunction(idfunction);
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(RoleFunctionsDTO.Translate(row));
                }
            }
            return lstDto;
        }
        #endregion

        #region CHEMISTWAREHOUSE
        public List<ChemistWareHouseDTO> ChemistWareHouse_SelectAll()
        {
            var lstDto = new List<ChemistWareHouseDTO>();
            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(ChemistWareHouseDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public ChemistWareHouseDTO ChemistWareHouse_SelectByID(int id)
        {
            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return ChemistWareHouseDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool ChemistWareHouse_Insert(ChemistWareHouseDTO obj)
        {
            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool ChemistWareHouse_Delete(int id)
        {
            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool ChemistWareHouse_Update(ChemistWareHouseDTO obj)
        {
            var rpt = new ChemistWareHouseDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        #endregion

        #region CUSTOMER
        public List<CustomerDTO> Customer_SelectAll()
        {
            var lstDto = new List<CustomerDTO>();
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(CustomerDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public CustomerDTO Customer_SelectByID(int id)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CustomerDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Customer_Insert(CustomerDTO obj)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Customer_Delete(int id)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Customer_Update(CustomerDTO obj)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }
        public CustomerDTO Customer_SelectByUserName(string username)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByUserName(username);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CustomerDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public CustomerDTO Customer_SelectByUserNameAndPassword(string username, string password)
        {
            var rpt = new CustomerDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByUserNameAndPassword(username, password);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CustomerDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        #endregion

        #region CATEGORY
        public List<CategoryDTO> Category_SelectAll()
        {
            var lstDto = new List<CategoryDTO>();
            var rpt = new CategoryDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectAll();
            if (objDS != null)
            {
                foreach (DataRow row in objDS.Tables[0].Rows)
                {
                    lstDto.Add(CategoryDTO.Translate(row));
                }
            }
            return lstDto;
        }
        public CategoryDTO Category_SelectByID(int id)
        {
            var rpt = new CategoryDAO(GlobalVariables.DbConnectionString);
            var objDS = rpt.SelectByID(id);
            if (objDS != null)
            {
                if (objDS.Tables[0].Rows.Count > 0)
                {
                    return CategoryDTO.Translate(objDS.Tables[0].Rows[0]);
                }
            }
            return null;
        }
        public bool Category_Insert(CategoryDTO obj)
        {
            var rpt = new CategoryDAO(GlobalVariables.DbConnectionString);
            return rpt.Insert(obj);
        }
        public bool Category_Delete(int id)
        {
            var rpt = new CategoryDAO(GlobalVariables.DbConnectionString);
            return rpt.Delete(id);
        }
        public bool Category_Update(CategoryDTO obj)
        {
            var rpt = new CategoryDAO(GlobalVariables.DbConnectionString);
            return rpt.Update(obj);
        }

        #endregion 

    }
}
